package object;

/**
 * Created with IntelliJ IDEA.
 * ClassName: UserTest
 * Package: object
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-11-22
 * Time: 22:44
 */

public class UserTest {

    public static void main(String[] args) {
        User user = new User("Tom",12);
        User user1 = new User("Tom",12);

        //自定义的类 在没有重写equals 使用Object
        System.out.println(user.equals(user1));

    }

}

class User{
    String name;
    int age;

    public User(){}

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object obj) {
        //快速判断 调用的 和 传来的参数 地址一样 那么就是一样的
        if (this == obj){
            return true;
        }

        //
        if (obj instanceof User){
            User user = (User)obj;
            if (this.age == user.age && this.name.equals(user.name)){
                return true;
            }else {
                return false;
            }
        }
        return false;

    }
}
